const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin

module.exports = {
	// 模式：production 生产模式 development 开发模式 none 
	mode:'development',
	devtool:'inline-source-map',
	// 入口:被打包的文件名
	entry:'./src/index.js',
	// 出口：打包到的目标位置
	output:{
		// filename:'dist.js', //打包的文件名称
		filename:'[name].[contenthash].js', //随机打包文件名称
		path:path.resolve(__dirname,'dist') //打包的文件目录
	},
	//路径别名
	resolve:{
		alias:{
			utils:path.resolve(__dirname,'src/utils')
		}
	},
	//压缩代码，并加入加密字符
	optimization:{
		minimize:true,
		minimizer:[new TerserWebpackPlugin()]
	},
	devServer:{
		static:"./dist",
	},
	plugins:[new htmlWebpackPlugin({
		title:'人员列表'
	}),new BundleAnalyzerPlugin()],
	module:{
		rules:[
			{
				test:/.css$/i,
				use:['style-loader','css-loader']
			},
			{
				test:/.(png|svg|jpg|jpeg|gif)$/i,
				type:'asset/resource'
			},
			{
				test:/\.js$/i,
				exclude:/node_modules/,
				use:{
					loader:'babel-loader',
					options:{
						presets:['@babel/preset-env']
					}
				}
			}
		]
	}
}